<template>
	<!--
    	作者：offline
    	时间：2018-09-12
    	描述：会计对账单审核tabs页组件
	-->
	<div class="m-view-accountApplyComponents m-window" id="accApp">
		<!--抬头-->
		<el-form
			ref="headerRuleForm"
			label-width="60px"
			:inline-message="true"
			label-position="left"
			class="m-headerForm"
		>
			<el-row :gutter="10">
				<el-col :span="7">
					<el-form-item label="会计对账单号" class="rightItem" label-width="100px">
						<el-input v-model="accountCode" placeholder="会计对账单号" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="8">
					<el-form-item label="供应商" class="rightItem">
						<el-input v-model="supplierName" placeholder="供应商" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="2" v-if="rollBack_show" class="m-floatright-col">
					<el-button type="primary" @click="rollBackAccountData">退回</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright-col">
					<el-button type="primary" @click="look">预览</el-button>
				</el-col>
				<el-col :span="2" class="m-floatright-col">
					<el-button @click="cancel()">返回</el-button>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-col :span="7">
					<el-form-item label="客户" class="rightItem" v-if="labelShow" label-width="100px">
						<el-input v-model="customer" placeholder="客户" disabled></el-input>
					</el-form-item>
					<el-form-item label="公司" class="rightItem" v-if="companyLabelShow" label-width="100px">
						<el-input v-model="comName" placeholder="客户" disabled></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="17">
					<el-form-item label="备注" class="rightItem">
						<el-input placeholder="请输入备注(可编辑200字)" v-model="remark" maxlength="200" :disabled="inputDis"></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="10">
				<el-col :span="7">
					<el-form-item label="申请日期" class="rightItem" label-width="100px">
						<el-date-picker
							v-model="applyDate"
							type="date"
							placeholder="申请日期"
							value-format="yyyy-MM-dd HH:mm:ss"
							disabled
						></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="17">
					<el-form-item label="不符项" class="rightItem">
						<el-input
							placeholder="存在对账不符时可填写(可编辑100字)"
							v-model="unConMemo"
							maxlength="100"
							:disabled="inputDis"
						></el-input>
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<!-- 余额 -->
		<div class="m-total">
			<div class="balance">
				<span>
					余额：
					<samp style="color:red" v-text="balance"></samp>元
				</span>
			</div>
		</div>
		<!--发票详情-->
		<div class="m-mainContent m-top3">
			<el-tabs type="card">
				<el-tab-pane label="对账详情">
					<div class="m-agTable">
						<!--实物对账单-->
						<!-- <ag-grid-vue
              class="m-agTableContent ag-theme-balham"
              :gridOptions="invoiceDetailsGridOptions"
              :columnDefs="invoiceDetailsColumnDefs"
              :rowData="invoiceDetailsRowData"
              rowSelection="single"
              v-loading="loading"
              height="300"
						></ag-grid-vue>-->
						<ag-grid-component
							ref="agGridComponent"
							:getColumnDefs="invoiceDetailsColumnDefs"
							:getRowSelection="'single'"
							:tableName="'accountAudit'"
							:getGridOptions="invoiceDetailsGridOptions"
							:getRowData="invoiceDetailsRowData"
							:isColFit="true"
							v-loading="loading"
							:systemInfo="$systemInfo"
						></ag-grid-component>
					</div>
				</el-tab-pane>
				<el-tab-pane label="审批意见" v-if="pageLayOut!='add'&&signInfo.length>0">
					<sign-option-tab :signInfo="signInfo"></sign-option-tab>
				</el-tab-pane>
			</el-tabs>
		</div>

		<!--签署文件预览-弹框-->
		<el-dialog
			:title="title"
			:visible.sync="dialogVisible"
			width="500px"
			top="50px"
			v-dialogDrag
			:before-close="handleClose2"
			:close-on-click-modal="false"
			:close-on-press-escape="false"
			:show-close="!btnDis"
			class="m-reconciliationModel"
		>
			<el-row :gutter="10" v-loading="btnDis">
				<el-col :span="24" v-if="accord_show">
					<p>致{{sup_name}}：</p>
					<p
						style="text-indent:25px;"
					>我公司按照制度的要求，应当询证与贵公司的往来帐项等事项。下列信息出自我公司账簿记录，如与贵公司记录相符，请贵公司签署本函予以确认。若无特别注明，金额币种均为人民币，单位均为元。</p>
					<p>我公司与贵公司 {{sDate}} 至 {{eDate}} 往来账项列示如下：</p>
				</el-col>
				<el-col :span="24" v-if="inconformity_show">
					<p>致{{sup_name}}：</p>
					<p
						style="text-indent:25px;"
					>我公司按照制度的要求，应当询证与贵公司的往来帐项等事项。下列信息出自我公司账簿记录，如有不符，请贵公司签署本函，并与我公司相关工作人员确认不符项目或与我公司有关的未列入本函的其他项目。若无特别注明，金额币种均为人民币，单位均为元。</p>
					<p>我公司与贵公司 {{sDate}} 至 {{eDate}} 往来账项列示如下：</p>
				</el-col>
				<el-col :span="24">
					<el-table :data="tD_account" size="mini" border style="width: 100%; margin-bottom:20px;">
						<el-table-column prop="createDate" label="截止日期" width="90"></el-table-column>
						<el-table-column prop="initCharge" label="上期金额" width="100"></el-table-column>
						<el-table-column prop="handleCharge" label="本期应付金额" width="100"></el-table-column>
						<el-table-column prop="alreadyCharge" label="本期已付金额" width="100"></el-table-column>
						<el-table-column prop="reconcyAmount" label="期末余额" width="100"></el-table-column>
						<el-table-column prop="debt_type" label="欠款性质" width="70"></el-table-column>
						<el-table-column prop="contract_code" label="相应合同名称及编号" width="100"></el-table-column>
						<el-table-column prop="pay_date" label="支付日期" width="90"></el-table-column>
						<el-table-column prop="pay_type" label="支付方式" width="110"></el-table-column>
					</el-table>
				</el-col>
				<el-col
					:span="24"
					style="border-bottom:1px solid #ccc; margin-bottom:10px; padding-bottom:35px; text-align:right;"
				>
					<p>甲方：{{com_name}}</p>
					<p style="padding-right:145px;">盖章：</p>
				</el-col>
				<el-col :span="12" v-if="accord_show">
					<p style="padding-bottom: 40px;">信息证明无误。</p>
					<p>乙方：{{sup_name}}</p>
					<p>签章：</p>
				</el-col>
				<el-col :span="24" v-if="inconformity_show">
					<p>{{unConMemo}}</p>
					<p style="padding-bottom: 40px;">以上信息不符。</p>
					<p>乙方：{{sup_name}}</p>
					<p>签章：</p>
				</el-col>
			</el-row>
			<el-row :gutter="10" style="padding-bottom:15px;">
				<el-col :span="5" v-if="audit_show">
					<el-button type="primary" @click="audit" :disabled="btnDis">审核</el-button>
					<!--auditAccountData-->
				</el-col>
			</el-row>
		</el-dialog>
	</div>
</template>

<script>
import _Api from "@/api";
import localeText from "@/i18n/agGridText";
import Vue from "vue";
import waterfall from "async-es/waterfall";
import constant from "@/public/constant";
import supplierInfo from "@/public/supplierInfo.js";
//  import serviceTime from "@/public/serverTime.js";
import NumericEditorComponent from '@/components/NumericEditorComponent.js';
import DecimalEditorComponent from '@/components/DecimalEditorComponent.js';
import DatePickerComponent from '@/components/DatePickerComponent.js';
import SelectorComponents from '@/components/SelectorComponents.js';
import SignOptionTab from "./common/signOptionTab";
import Msg from "@/public/message.js";
import { startPrint } from 'lesso-common/webprint';
import fileStream from "@/public/fileStream";
import apienv from '@/api/env';
import aes from '@/public/aes';
import gridOptions from 'lesso-common/public/gridOptions';


const ENV = apienv[constant.appenv]

const operator = Vue.extend({
	template: `<span>
		<el-button type="text" @click="delDetails" class="rendererClass" size="mini" v-if="delDetailsShow">删除</el-button>	
		</span>`,
	data () {
		return {
			delDetailsShow: operator.delDetailsShow
		}
	},
	methods: {
		delDetails () {
			this.params.context.componentParent.deleteDetails(this.params.node.data);
		}
	}
})

export default {
	data () {
		return {
			btnDis: false,
			accountCode: "",
			supplierName: "",
			supplierCode: "",
			optionShow: true,
			selCompanyCode: "",
			comOptions: [],
			labelShow: false,
			customer: "",
			companyLabelShow: false,
			comName: "",
			remark: "",
			unConMemo: "",
			inputDis: false,
			invoiceDetailsColumnDefs: [],
			invoiceDetailsRowData: [],
			loading: false,
			phyGoodsDialogVisible: false,
			selCompanyName: "",
			applyDate: "",
			diaLoading: false,
			accountBtnShow: false,
			supplierBtnShow: true,
			saveBtnShow: true,
			billTotalMoney: 0,
			invoiceTotalMoney: 0,
			balance: 0,
			applySDate: "",
			applyEDate: "",
			phyCode: "",
			currentPage: 1,
			pageSize: 30,
			total: 0,
			physicalGoodSelRows: [],//实物对账选择数组
			invoiceSelRows: [],//发票选择数组
			invoiceSelRowsDetail: {},
			rollBack_show: true,//退回按钮的显示
			audit_show: true,//审核按钮的显示
			abandonBtn: false,
			//unConMemo:"",//不符描述
			title: "对账函",
			dialogVisible: false,//签署文件预览
			accord_show: true,//符合模板
			inconformity_show: true,//不符合模板
			sup_name: "",
			com_name: "",
			sDate: "",  //开始日期
			eDate: "",  //截止日期
			abortDate: "",//表格中的截止日期
			tD_account: [],
			//  审批意见相关
			signInfo: []
		}
	},
	watch: {
		dialogSize (val) {
			this.dialogSize = val;
			this.$refs.agGridComponent.gridOptions.api.sizeColumnsToFit();
		},
		billTotalMoney (val) {
			this.billTotalMoney = this.billTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		},
		invoiceTotalMoney () {
			this.invoiceTotalMoney = this.invoiceTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		},
		balance (val) {
			this.balance = this.balance.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
		}
	},
	methods: {
		cancel (signMode = '') {
			//取消
			let obj = {
				signMode: signMode,
				isCancel: true
			}
			this.$emit("cancelComponents", obj);
		},
		look () {
			//预览签署文件
			this.tD_account[0].contract_code = this.invoiceSelRowsDetail.contractNo;
			this.dialogVisible = true;
		},
		handleClose2 (done) {
			done();
		},
		cancelDialog () {
			this.phyGoodsDialogVisible = false;
		},
		//添加合计栏在表格底部
		createData (count, prefix) {
			var result = [];
			for (let i = 0; i < count; i++) {
				result.push({
					gooAccNo: "合计",
					amount: this.billTotalMoney,
					invoiceMoney: this.invoiceTotalMoney
				})
			}
			return result;
		},
		//
		accAdd (arg1, arg2) {
			var r1, r2, m, c;
			try {
				r1 = arg1.toString().split(".")[1].length;
			}
			catch (e) {
				r1 = 0;
			}
			try {
				r2 = arg2.toString().split(".")[1].length;
			}
			catch (e) {
				r2 = 0;
			}
			c = Math.abs(r1 - r2);
			m = Math.pow(10, Math.max(r1, r2));
			if (c > 0) {
				var cm = Math.pow(10, c);
				if (r1 > r2) {
					arg1 = Number(arg1.toString().replace(".", ""));
					arg2 = Number(arg2.toString().replace(".", "")) * cm;
				} else {
					arg1 = Number(arg1.toString().replace(".", "")) * cm;
					arg2 = Number(arg2.toString().replace(".", ""));
				}
			} else {
				arg1 = Number(arg1.toString().replace(".", ""));
				arg2 = Number(arg2.toString().replace(".", ""));
			}
			return (arg1 + arg2) / m;
		},
		//
		invoiceCellValueChanged () {
			var that = this;
			this.invoiceTotalMoney = 0;
			this.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
				if (node.data.invoiceMoney)
					that.invoiceTotalMoney = that.accAdd(node.data.invoiceMoney, that.invoiceTotalMoney);
			});
			this.billTotalMoney = 0;
			for (let i = 0; i < this.invoiceSelRows.length; i++) {
				let beforeNo = this.invoiceSelRows[i].gooAccNo;
				let afterNo;
				if (this.invoiceSelRows[i + 1])
					afterNo = this.invoiceSelRows[i + 1].gooAccNo;
				if (afterNo) {
					if (beforeNo != afterNo)
						this.billTotalMoney += this.accAdd(this.billTotalMoney, this.invoiceSelRows[i].amount);
				} else {
					this.billTotalMoney += this.accAdd(this.billTotalMoney, this.invoiceSelRows[i].amount);
				}
			}
		},
		//获取会计对账详情
		getAccountDetails (params) {
			let obj = {
				accountNo: params.accountNo,
				id: params.id
			};
			var that = this;
			_Api.getAccountDetails(obj).then(function (response) {
				let data = response.data;
				if (data.code == "1") {
					if (data.rows.mAccountTotal.length > 0) {
						that.invoiceSelRows = data.rows.mAccountTotal.splice(0);
						that.invoiceSelRowsDetail = data.rows.tblAccountbill;
						that.$refs.agGridComponent.gridOptions.api.setRowData(that.invoiceSelRows);//data.rows.mAccountDetail
						that.invoiceTotalMoney = 0;
						that.billTotalMoney = 0;
						//从会计对账接口主表中获取对账函号
						that.setClickValue.accountCode = data.rows.tblAccountbill.accountCode;
						let count = 0;
						let list = [];
						that.$refs.agGridComponent.gridOptions.api.forEachNode(function (node) {
							count = 0;
							if (node.data.invoiceMoney) {
								that.invoiceTotalMoney = that.accAdd(node.data.invoiceMoney, that.invoiceTotalMoney);
								that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
							}
							for (let i = 0; i < list.length; i++) {
								if (list[i].gooAccNo == node.data.gooAccNo) {
									count++;
								}
							}
							if (count == 0) {
								list.push(node.data);
							}
						});
						for (let i = 0; i < list.length; i++) {
							that.billTotalMoney = that.accAdd(list[i].amount, that.billTotalMoney);
							that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));
						}
						if (that.pageLayOut == "edit") {
							if (that.setClickValue.billState > 1) {
								let col = that.$refs.agGridComponent.gridOptions.columnApi.getAllDisplayedColumns();
								for (let c in col) {
									col[c].colDef.editable = false;
								}
							}
						}
						that.billTotalMoney = that.billTotalMoney.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
					}
				} else {
					Msg.showErrorMsg(data.info);
				}
			}).catch((err) => {
				Msg.showErrorMsg(err.data.message);
			})
		},
		//获取供应商余额
		getSupplierBalance () {
			let obj = {};
			obj.companyCode = this.setClickValue.companyCode;//公司编码
			obj.supplierCode = this.setClickValue.supplierCode;//供应商编码
			obj.reconcyDate = this.setClickValue.createDate.substr(0, 10);
			var that = this;
			_Api.getSupplierBalance(obj).then(function (response) {
				let data = response.data;
				if (data.code == "1") {
					//余额
					that.balance = data.rows.balance || 0;
					that.$refs.agGridComponent.gridOptions.api.setPinnedBottomRowData(that.createData(1, "Bottom"));

					//文件签署预览-弹框
					that.sup_name = that.setClickValue.supplierName;
					that.unConMemo = that.setClickValue.unConMemo;//不符描述
					that.com_name = that.setClickValue.companyName;
					that.abortDate = data.rows.endDate; //截止日期
					var obj = [
						{
							createDate: data.rows.endDate,//截止日期-上个月最后一天
							initCharge: data.rows.beginning,//期初
							handleCharge: data.rows.handle,//应付
							alreadyCharge: data.rows.paid,//已付
							reconcyAmount: data.rows.balance,//余额
							debt_type: "应付账款",
							// contract_code:that.setClickValue.contract_code,
							contract_code: that.invoiceSelRowsDetail.contractNo,
							pay_date: "采购框架协议约定之日",
							pay_type: "汇票、电汇、信用证或其他"
						}
					];
					that.tD_account = obj;
					//
					if (data.rows.endDate != null && data.rows.endDate != "") {
						that.sDate = (new Date(data.rows.endDate).getMonth() + 1) + "月01日";
						that.eDate = (new Date(data.rows.endDate).getMonth() + 1) + "月" + new Date(data.rows.endDate).getDate() + "日";
					}
					//符合或不符合模板
					if (that.unConMemo == "") {
						that.accord_show = true;
						that.inconformity_show = false;
					}
					else {
						that.accord_show = false;
						that.inconformity_show = true;
					}
				}
				else {
					that.balance = 0;
				}
			})
		},
		//退回会计对账单
		rollBackAccountData () {
			var that = this;
			this.$prompt("审批意见", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				customClass: 'promitBox',
				inputType: 'textarea',
				inputValidator: (val) => {
					if (!val) {
						return '审批意见不能为空'
					}
				},
				distinguishCancelAndClose: true
			}).then(({ value }) => {
				var obj = {
					accountNo: that.setClickValue.accountNo,
					id: that.setClickValue.id,
					flag: 2,
					callflag: 2,
					modifyer: that.$global.user.employeeName,
					modifyerId: that.$global.user.id,
					confirmer: that.setClickValue.confirmer,
					confirmerId: that.setClickValue.confirmerId,
					supplierId: that.setClickValue.supplierId,
					companyId: that.setClickValue.companyId,
					signOption: value
				};
				_Api.putAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("操作成功")
						that.cancel(that.setClickValue.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
				})
			}).catch(() => {
			})
		},
		//弃审会计对账单
		abandonAccountData () {
			var that = this;
			this.$confirm("是否弃审该数据？", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				distinguishCancelAndClose: true
			}).then(() => {
				var obj = {
					accountNo: that.setClickValue.accountNo,
					id: that.setClickValue.id,
					flag: 4,
					callflag: 2,
					modifyer: that.$global.user.employeeName,
					modifyerId: that.$global.user.id,
					supplierId: that.setClickValue.supplierId,
					companyId: that.setClickValue.companyId
				};
				_Api.putAccountBill(obj).then(function (response) {
					let data = response.data;
					if (data.code == "1") {
						Msg.showSuccessMsg("操作成功")
						that.cancel(that.setClickValue.signMode);
					} else {
						Msg.showErrorMsg(data.info);
					}
				}).catch((err) => {
					Msg.showErrorMsg(err.data.message);
				})
			}).catch(() => {
			})
		},
		//审核会计对账单
		auditAccountData () {

			var that = this;
			this.$confirm("是否审核该数据？", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				distinguishCancelAndClose: true
			}).then(() => {
				that.btnDis = true;
				//上传签署文件
				var obj4 = {};
				obj4.supplierName = that.setClickValue.supplierName;//供应商
				obj4.companyName = that.setClickValue.companyName;//公司
				obj4.abortDate = that.abortDate; //that.setClickValue.createDate.substr(0,10);//对账日期
				obj4.contractNo = that.setClickValue.contractNo;//合同编号
				obj4.initCharge = that.tD_account[0].initCharge;//期初
				obj4.handleCharge = that.tD_account[0].handleCharge;//应付
				obj4.alreadyCharge = that.tD_account[0].alreadyCharge;//已付
				obj4.reconcyAmount = that.tD_account[0].reconcyAmount;//余额
				obj4.accountNo = that.setClickValue.accountNo;//会计单号
				obj4.beginDate = obj4.abortDate.substr(0, 8) + "01"; //开始日期
				obj4.endDate = obj4.abortDate; //截止日期
				obj4.userId = constant.userId; // 用户id
				obj4.userName = constant.userName; // 用户名  
				//判断是否有不符描述
				if (this.unConMemo == "") {
					obj4.telType = 1;//符合-文件类型
					obj4.nremark = "";
				}
				else {
					obj4.telType = 2;//不符合-文件类型
					obj4.nremark = this.unConMemo;
				}

				_Api.uploadSignFile(obj4).then(function (response) {
					var data_upload = response.data;
					if (data_upload.code == 1) {
						if (data_upload.total > 0) {
							//发起签署
							var myDate = new Date();
							myDate.setMonth(myDate.getMonth() + 1);
							var obj3 = {
								token: "",
								project: "SRM",
								create_by: that.$global.user.id, //操作用户
								doc: {
									doc_no: that.setClickValue.accountNo, //签署文件编号-会计对账单号
									send_id: "", //签署发起人Id
									title: data_upload.rows[0].orgName, //签署标题说明
									doc_path: data_upload.rows[0].fileName, //签署文档路径
									expire_date: myDate.toLocaleDateString(), //签署过期日期
									business_templet_id: "",//行业类型id
									scene_templet_id: "",//...
									segment_templet_id: "",//证据点id
									in_order: 0, //是否按顺序签署 0-否 1-是
									remarks: "" //备注-文件签署-测试
								},
								signerList: [
									{
										signer_id: "", //电子签帐号-公司
										position_type: 0, //定位类型 0-坐标定位 1-关键字定位
										sign_type: 0, //签署类型 0-单页Single 1 -多页Multi
										pos_x: 460.34375, //签署横坐标
										pos_y: 370.010416666667, //签署纵坐标
										segment_prop_id1: "", //签署方描述id-甲方
										segment_prop_id2: "", //签署方名称描述id-甲方
										sort: 0 //按顺序签署时
									},
									{
										signer_id: "", //电子签帐号-供应商
										position_type: 0, //定位类型 0-坐标定位 1-关键字定位
										sign_type: 0, //签署类型 0-单页Single 1 -多页Multi
										pos_x: 116.34375, //签署横坐标
										pos_y: 124.010416666667, //签署纵坐标
										segment_prop_id1: "", //签署方描述id-乙方
										segment_prop_id2: "", //签署方名称描述id-乙方
										sort: 1 //按顺序签署时
									}
								]
							};
							if (constant.appenv == "app") {
								//正式环境
								obj3.doc.business_templet_id = "3957bfbd-7815-48b5-bf2e-95be92d19e27";
								obj3.doc.scene_templet_id = "b1dd60f7-54e2-4ea2-8f27-614c77372d9e";
								obj3.doc.segment_templet_id = "d3687f4c-b511-435f-a8e9-be172928c50d";
								obj3.doc.send_id = that.setClickValue.ceSignAccount;//签署发起人
								obj3.signerList[0].signer_id = that.setClickValue.ceSignAccount;//电子签帐号-公司
								obj3.signerList[0].segment_prop_id1 = "377EF5D1-0053-462D-9005-BC06E2CDBF2C";//签署方描述id-公司
								obj3.signerList[0].segment_prop_id2 = "6F01ABFF-9082-4CC6-B6A0-73A907E40B03";//签署方名称描述id-公司
								obj3.signerList[1].signer_id = that.setClickValue.seSignAccount;//电子签帐号-供应商
								obj3.signerList[1].segment_prop_id1 = "4B34162D-779D-47FC-B2D4-DF2EE307BB64";//签署方描述id-供应商
								obj3.signerList[1].segment_prop_id2 = "E3C39A9E-CD62-4C12-9B83-7E1E2CA63126";//签署方名称描述id-供应商
							}
							else if (constant.appenv == "qas") {
								//测试环境
								obj3.doc.business_templet_id = "1faf4a70-6011-4b3c-8a5b-c6a096477f61";
								obj3.doc.scene_templet_id = "caa4f4f3-095a-4719-bcc8-fcca0179e478";
								obj3.doc.segment_templet_id = "12972e15-dec2-4c01-8027-a6b6872be437";
								obj3.doc.send_id = that.setClickValue.ceSignAccount;//签署发起人
								obj3.signerList[0].signer_id = that.setClickValue.ceSignAccount;//电子签帐号-公司
								obj3.signerList[0].segment_prop_id1 = "060112A6-2AD6-42B2-86EE-2EBF92658472";//签署方描述id-公司
								obj3.signerList[0].segment_prop_id2 = "11E86175-B6D5-4679-8109-D8B776D54C46";//签署方名称描述id-公司
								obj3.signerList[1].signer_id = that.setClickValue.seSignAccount;//电子签帐号-供应商
								obj3.signerList[1].segment_prop_id1 = "33AC7A74-D444-48E4-AA65-0695BC69F3AF";//签署方描述id-供应商
								obj3.signerList[1].segment_prop_id2 = "42E50960-E17F-4214-8073-65761277DEAB";//签署方名称描述id-供应商
							}
							else {
								//开发环境
								obj3.doc.business_templet_id = "1faf4a70-6011-4b3c-8a5b-c6a096477f61";
								obj3.doc.scene_templet_id = "caa4f4f3-095a-4719-bcc8-fcca0179e478";
								obj3.doc.segment_templet_id = "12972e15-dec2-4c01-8027-a6b6872be437";
								// obj3.doc.send_id = "LS1010";//签署发起人
								obj3.doc.send_id = "00033525"
								// obj3.signerList[0].signer_id = "yuanfeng";
								obj3.signerList[0].signer_id = "00033525"
								obj3.signerList[0].segment_prop_id1 = "060112A6-2AD6-42B2-86EE-2EBF92658472";//签署方描述id-公司
								obj3.signerList[0].segment_prop_id2 = "11E86175-B6D5-4679-8109-D8B776D54C46";//签署方名称描述id-公司
								// obj3.signerList[1].signer_id = "lanshan";
								obj3.signerList[1].signer_id = "00034071"
								obj3.signerList[1].segment_prop_id1 = "33AC7A74-D444-48E4-AA65-0695BC69F3AF";//签署方描述id-供应商
								obj3.signerList[1].segment_prop_id2 = "42E50960-E17F-4214-8073-65761277DEAB";//签署方名称描述id-供应商
							}

							_Api.BeSign(obj3).then(function (response) {
								var data_sign = response.data;
								if (data_sign.Code == 0) {
									//发起签署成功
									//已审状态
									var obj = {
										accountNo: that.setClickValue.accountNo,
										id: that.setClickValue.id,
										flag: 3,//审核
										callflag: 2,//财务经理页面调用标识
										confirmer: that.$global.user.employeeName,
										confirmerId: that.$global.user.id
									};
									//修改审批状态
									_Api.putAccountBill(obj).then(function (response) {
										let data = response.data;
										if (data.code == "1") {
											Msg.showSuccessMsg("操作成功")
											that.cancel();
										}
										else {
											Msg.showErrorMsg("操作失败！");
										}
									})//修改审核状态接口
								}
								else {
									// that.$alert(data_sign.Error, {
									//     showClose: false,
									//     confirmButton: "确定",
									//     customClass: "alertFailure"
									// });
									Msg.showErrorMsg(data_sign.Error);
								}
							})
								.catch(() => {
									Msg.showErrorMsg("请求失败！");
								});
						}
					}
					else {
						// that.$alert(data_upload.info, {
						//     showClose: false,
						//     confirmButton: "确定",
						//     customClass: "alertFailure"
						// });
						Msg.showErrorMsg(data_upload.info);
					}
					that.btnDis = false;
				});
			}).catch(() => { })
		},
		audit () {
			//审核对账函 by lxh 20190109

			var that = this;
			this.$prompt("审批意见", "消息提示", {
				confirmButtonText: "确定",
				cancelButtonText: "取消",
				customClass: 'promitBox',
				inputValue: '同意',
				inputType: 'textarea',
				distinguishCancelAndClose: true
			}).then(({ value }) => {
				if (!value || !value.trim()) {
					Msg.showErrorMsg('审批意见不能为空！')
					return
				}
				that.btnDis = true;
				if (that.setClickValue.signMode == 0) {
					// 线上签章审批流程
					waterfall([
						function putAccountBill (callback) {
							that.changeAccountAudit(value).then(_ => {
								callback()
							}).catch(err => {
								Msg.showErrorMsg(err)
							})
						},
						function uploadSignFile (callback) {
							var obj4 = {};
							obj4.supplierName = that.setClickValue.supplierName;//供应商
							obj4.companyName = that.setClickValue.companyName;//公司
							obj4.abortDate = that.abortDate; //that.setClickValue.createDate.substr(0,10);//对账日期
							// obj4.contractNo = that.setClickValue.contractNo;//合同编号
							obj4.accountCode = that.invoiceSelRowsDetail.accountCode;//会计对账函号
							obj4.contractNo = that.invoiceSelRowsDetail.contractNo;//合同编号
							obj4.contractName = that.invoiceSelRowsDetail.contractName;//合同名称
							obj4.initCharge = that.tD_account[0].initCharge;//期初
							obj4.handleCharge = that.tD_account[0].handleCharge;//应付
							obj4.alreadyCharge = that.tD_account[0].alreadyCharge;//已付
							obj4.reconcyAmount = that.tD_account[0].reconcyAmount;//余额
							obj4.accountNo = that.setClickValue.accountNo;//会计单号
							obj4.beginDate = obj4.abortDate.substr(0, 8) + "01"; //开始日期
							obj4.endDate = obj4.abortDate; //截止日期
							obj4.userId = constant.userId; // 用户id
							obj4.userName = constant.userName; // 用户名 
							obj4.memo = value; //审批意见                      
							//判断是否有不符描述
							if (that.unConMemo == "") {
								obj4.telType = 1;//符合-文件类型
								obj4.nremark = "";
							}
							else {
								obj4.telType = 2;//不符合-文件类型
								obj4.nremark = that.unConMemo;
							}
							_Api.uploadSignFile(obj4).then(function (response) {
								var data_upload = response.data;
								if (data_upload.code === 1) {
									if (data_upload.total > 0) {
										callback(null, data_upload);
									}
								} else {
									Msg.showErrorMsg(data_upload.info)
									that.btnDis = false
									//   that.updateAccountState(that.setClickValue.id).then(data => {
									//     that.btnDis = false
									//   }).catch(err => {
									//     Msg.showErrorMsg(err)
									//   })
								}
							}).catch((err) => {
								Msg.showErrorMsg(err.data.info);
								that.btnDis = false
								// that.updateAccountState(that.setClickValue.id).then(data => {
								//   that.btnDis = false
								// }).catch(err => {
								//   Msg.showErrorMsg(err)
								// })
							})
						},
						function beSign (data, callback) {
							//发起签署
							var myDate = new Date();
							myDate.setMonth(myDate.getMonth() + 1);
							var obj3 = {
								token: "",
								project: "SRM",
								create_by: that.$global.user.id, //操作用户
								doc: {
									doc_no: that.setClickValue.accountNo, //签署文件编号-会计对账单号
									id: that.setClickValue.id,//对账单id
									send_id: "", //签署发起人Id
									title: data.rows[0].orgName, //签署标题说明
									doc_path: data.rows[0].fileName, //签署文档路径
									expire_date: myDate.toLocaleDateString(), //签署过期日期
									business_templet_id: "",//行业类型id
									scene_templet_id: "",//...
									segment_templet_id: "",//证据点id
									in_order: 0, //是否按顺序签署 0-否 1-是
									remarks: "" //备注-文件签署-测试
								},
								signerList: [
									{
										signer_id: "", //电子签帐号-公司
										position_type: 0, //定位类型 0-坐标定位 1-关键字定位
										sign_type: 1, //签署类型 0-单页Single 1 -多页Multi
										pos_page: 1,//签署页码
										pos_x: 460.34375, //签署横坐标
										pos_y: 370.010416666667, //签署纵坐标
										segment_prop_id1: "", //签署方描述id-甲方
										segment_prop_id2: "", //签署方名称描述id-甲方
										sort: 0 //按顺序签署时
									},
									{
										signer_id: "", //电子签帐号-供应商
										position_type: 0, //定位类型 0-坐标定位 1-关键字定位
										sign_type: 1, //签署类型 0-单页Single 1 -多页Multi
										pos_page: 1, //签署页码
										pos_x: 116.34375, //签署横坐标
										pos_y: 124.010416666667, //签署纵坐标
										segment_prop_id1: "", //签署方描述id-乙方
										segment_prop_id2: "", //签署方名称描述id-乙方
										sort: 1 //按顺序签署时
									}
								]
							};
							if (constant.appenv == "app") {
								//正式环境
								obj3.doc.business_templet_id = "3957bfbd-7815-48b5-bf2e-95be92d19e27";
								obj3.doc.scene_templet_id = "b1dd60f7-54e2-4ea2-8f27-614c77372d9e";
								obj3.doc.segment_templet_id = "d3687f4c-b511-435f-a8e9-be172928c50d";
								obj3.doc.send_id = that.setClickValue.ceSignAccount;//签署发起人
								obj3.signerList[0].signer_id = that.setClickValue.ceSignAccount;//电子签帐号-公司
								obj3.signerList[0].segment_prop_id1 = "377EF5D1-0053-462D-9005-BC06E2CDBF2C";//签署方描述id-公司
								obj3.signerList[0].segment_prop_id2 = "6F01ABFF-9082-4CC6-B6A0-73A907E40B03";//签署方名称描述id-公司
								obj3.signerList[1].signer_id = that.setClickValue.seSignAccount;//电子签帐号-供应商
								obj3.signerList[1].segment_prop_id1 = "4B34162D-779D-47FC-B2D4-DF2EE307BB64";//签署方描述id-供应商
								obj3.signerList[1].segment_prop_id2 = "E3C39A9E-CD62-4C12-9B83-7E1E2CA63126";//签署方名称描述id-供应商
							}
							else if (constant.appenv == "qas"||constant.appenv == "dev") {
								//测试环境
								obj3.doc.business_templet_id = "337c7fb3-1f3d-4b11-a7bb-7f563cc2892d";
								obj3.doc.scene_templet_id = "27e3ce48-02d9-4191-9b67-3ab9527e0f54";
								obj3.doc.segment_templet_id = "1ac34607-bb27-47ba-9852-b64df40066f7";
								obj3.doc.send_id = that.setClickValue.ceSignAccount;//签署发起人
								obj3.signerList[0].signer_id = that.setClickValue.ceSignAccount;//电子签帐号-公司
								obj3.signerList[0].segment_prop_id1 = "40CA0928-4F03-4682-9B90-DF394311BDBF";//签署方描述id-公司
								obj3.signerList[0].segment_prop_id2 = "A67726A2-B2FF-4785-9BAC-52673D9285CB";//签署方名称描述id-公司
								obj3.signerList[1].signer_id = that.setClickValue.seSignAccount;//电子签帐号-供应商
								obj3.signerList[1].segment_prop_id1 = "6CF5AB34-D987-429F-A325-E7917DECFAC8";//签署方描述id-供应商
								obj3.signerList[1].segment_prop_id2 = "65C542A1-E647-40A6-B8C1-B6E5957195B2";//签署方名称描述id-供应商
							}
							// else {
							// 	//开发环境
							// 	obj3.doc.business_templet_id = "337c7fb3-1f3d-4b11-a7bb-7f563cc2892d";
							// 	obj3.doc.scene_templet_id = "27e3ce48-02d9-4191-9b67-3ab9527e0f54";
							// 	obj3.doc.segment_templet_id = "1ac34607-bb27-47ba-9852-b64df40066f7";
                            //     // obj3.doc.send_id = "LS1010";//签署发起人
                            //      obj3.doc.send_id = that.setClickValue.ceSignAccount;
                            //     // obj3.signerList[0].signer_id = "yuanfeng";
                            //     obj3.signerList[0].signer_id = that.setClickValue.ceSignAccount; //电子签帐号-公司
							// 	obj3.signerList[0].segment_prop_id1 = "40CA0928-4F03-4682-9B90-DF394311BDBF";//签署方描述id-公司
							// 	obj3.signerList[0].segment_prop_id2 = "A67726A2-B2FF-4785-9BAC-52673D9285CB";//签署方名称描述id-公司
                            //     // obj3.signerList[1].signer_id = "lanshan";
                            //     obj3.signerList[1].signer_id = that.setClickValue.seSignAccount; //电子签帐号-供应商
							// 	obj3.signerList[1].segment_prop_id1 = "6CF5AB34-D987-429F-A325-E7917DECFAC8";//签署方描述id-供应商
							// 	obj3.signerList[1].segment_prop_id2 = "65C542A1-E647-40A6-B8C1-B6E5957195B2";//签署方名称描述id-供应商
							// }
							_Api.BeSign(obj3).then(function (response) {
								var data_sign = response.data;
								if (data_sign.Code == 0) {
									that.invoiceSelRowsDetail.docId = data_sign.Data.Doc_id;
									//   callback(null);
									Msg.showSuccessMsg("审核成功")
									that.cancel(that.setClickValue.signMode)
									that.btnDis = false
								} else {
									// that.$alert(data_sign.Error, {
									//     showClose: false,
									//     confirmButton: "确定",
									//     customClass: "alertFailure"
									// });
									Msg.showErrorMsg(data_sign.Error);
									// that.btnDis = false
									  that.updateAccountState(that.setClickValue.id).then(data => {
									    that.btnDis = false
									  }).catch(err => {
									    Msg.showErrorMsg(err)
									  })
								}
							}).catch((err) => {
								Msg.showErrorMsg(data_sign.Error);
								// that.btnDis = false
								that.updateAccountState(that.setClickValue.id).then(data => {
								  that.btnDis = false
								}).catch(err => {
								  Msg.showErrorMsg(err)
								})
							})
						}
					])
				} else if (that.setClickValue.signMode == 1) {
					// 线下审批
					that.changeAccountAudit(value).then(_ => {
						let type = that.unConMemo ? 'accountLetter_1' : 'accountLetter'
						that.printAccount(type)
						that.btnDis = false;
						that.cancel(that.setClickValue.signMode);
					}).catch(err => {
						that.btnDis = false;
						Msg.showErrorMsg(err);
					})
				}
			}).catch(() => { })
		},
		// 修改对账单审核状态
		changeAccountAudit (option) {
			var obj = {
				accountNo: this.setClickValue.accountNo,
				id: this.setClickValue.id,
				flag: 3,//审核
				callflag: 2,//财务经理页面调用标识
				confirmer: this.$global.user.employeeName,
				confirmerId: this.$global.user.id,
				supplierId: this.setClickValue.supplierId,
				companyId: this.setClickValue.companyId,
				//添加部分字段以进行对账函的上传
				companyCode: this.setClickValue.companyCode,
				supplierCode: this.setClickValue.supplierCode,
				accountCode: this.setClickValue.accountCode,
				signOption: option,
				modifyer: this.$global.user.employeeName,
				modifyerId: this.$global.user.id
			}
			return new Promise((resolve, reject) => {
				// 修改审批状态   
				_Api.putAccountBill(obj).then((response) => {
					let data = response.data;
					if (data.code == "1") {
						resolve()
					} else {
						reject(data.info)
					}
				}).catch(err => {
					reject(err.data.message)
				})
			})
		},
		// 签署失败更改对账单状态为未审核
		updateAccountState (accountId) {
			return new Promise((resolve, reject) => {
				_Api.updateAccountState({ id: accountId }).then(({ data }) => {
					if (data.code == 1) {
						resolve()
					} else {
						reject(data.info)
					}
				}).catch(err => {
					reject(err.data.message)
				})
			})
		},
		// 签署失败撤回签署
		recallSignFlag (ceSignAccount, docId) {
			let objSign = {
				account: this.invoiceSelRowsDetail.ceSignAccount,
				doc_id: this.invoiceSelRowsDetail.docId,
				project: 'SRM',
				reason_msg: '文档重复，数据异常要求撤回！',
				token: ''
			}
			return new Promise((resolve, reject) => {
				//   审核异常，撤回审核
				_Api.recallSignFlag(objSign).then((response) => {
					let data = response.data
					if (data.code === 1) {
						this.btnDis = false
						Msg.showPopMsg("提示：审核过程中存在异常，已撤回审核！")
					} else {
						this.btnDis = false
						Msg.showErrorMsg(data.info)
					}
				}).catch((err) => {
					this.btnDis = false
					Msg.showErrorMsg(err)
				})
			})
		},
		// 打印对账函
		printAccount (type) {
			if (constant.userAgent == 'web') {
				fileStream.getFileInfo(type).then((data) => {
					startPrint({
						basicUrl: ENV['srm'], //权限接口地址
						reportUrl: `${ENV['srm']}download2?viewPath=${data.url}&groupName=${data.groupName}`, //打印模板地址
						dataUrl: 'tblAccountbill/letterInfo', //数据接口地址
						params: {
							'token': '',
							'id': this.setClickValue.id
						}, //参数对象
						printType: 'preview'     // 打印方式print直接打印，preview先预览
					})
				}).catch((err) => {
					Msg.showErrorMsg(err)
				})
			} else {
				this.getPrintData(this.setClickValue, type)
			}
		},
		// 客户端打印
		getPrintData (row, type) {
			const ENCRYPT_KEY = 'lesso2128token11'
			waterfall([
				(callback) => {
					this.$http.getPrintToken().then(({ data }) => {
						let token = aes.encrypt(data, ENCRYPT_KEY);
						callback(null, token);
					}).catch(err => {
						Msg.showErrorMsg(err.data.message)
					})
				},
				(token, callback) => {
					this.$http.getPrintAccountData({ id: row.id, token: token }).then(({ data }) => {
						let printData = data.rows
						callback(null, printData)
					}).catch(err => {
						Msg.showErrorMsg(err.data.message)
					})
				},
				(printData, callback) => {
					if (constant.printType == 'local') {
						ipcRenderer.send("IPCR_M_PRINTLOCAL", {
							type: type,
							rows: printData,
							optype: 'pr',
							isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
						});
					} else {
						fileStream.getFileInfo(type, printData).then((data) => {
							ipcRenderer.send("IPCR_M_PRINT", {
								type: type,
								rows: printData,
								groupName: data.groupName,
								optype: "pr",
								url: data.url,
								isdefaultp: 1//控制是否直接打印,0为选择打印、1为直接打印
							})
						}).catch((err) => {
							Msg.showErrorMsg(err)
						})
					}
				}
			])
		},
		//控制按钮
		getBtnAuth () {
			var that = this;
			var obj = {
				resultType: "0",
                code: 'accountBill',
                authClientCode:constant.authCode.code,
                authTenantCode:constant.authCode.tcode
			}
			_Api.getUserAuthMenu(obj).then(function (response) {
				let data = response.data;
				if (data.code == "1") {
					if (data.total > 0) {
						if (that.$global.user.userTypeId != "4") {
							let billState = that.setClickValue.billState;
							// let signState = that.setClickValue.signState;
							for (let i in data.rows) {
								//未审
								if (data.rows[i].code == "rollBackAccountData" && billState == 3)
									that.rollBack_show = true;//退回按钮的显示状态
								//已审
								else if (data.rows[i].code == "rollBackAccountData" && billState == 4)
									that.rollBack_show = false;//
								//未审
								if (data.rows[i].code == "auditAccountData" && billState == 3)
									that.audit_show = true;//审批按钮的显示状态
								//已审
								else if (data.rows[i].code == "auditAccountData" && billState == 4)
									that.audit_show = false;//
								//	        						if(data.rows[i].code == "rollBackAccountData" && billState == 3)
								//	        							that.rollBack_show = true;
								//	        						if(data.rows[i].code == "abandonAccountData" && billState == 4 && signState == 1)
								//	        							that.abandonBtn = true;
							}
						}
					} else {
						that.rollBack_show = false;
						that.audit_show = false;
						that.abandonBtn = false;
					}
				}
			})
		},
		// 获取审批意见内容
		getAuditOptionData () {
			_Api.getSignOption({ billNo: this.accountCode }).then(({ data }) => {
				if (data.code == 1) {
					this.signInfo = data.rows
				} else {
					Msg.showErrorMsg(data.info)
				}
			}).catch(err => {
				Msg.showErrorMsg(err.data.message)
			})
		}
	},
	mounted () {
		var that = this;
		this.getBtnAuth();
		supplierInfo.getUserInfo(this.$global.user.userName).then((supplierInfo) => {
			that.supplierInfo = supplierInfo;
			if (that.supplierInfo.length > 0)
				that.supplierName = that.supplierInfo[0].supplierName + " (" + that.supplierInfo[0].mainAccount + ")";
		});

		//浏览会计对账单
		if (this.pageLayOut == "edit") {
			this.accountCode = this.setClickValue.accountNo;//会计对账单号
			this.applyDate = new Date(this.setClickValue.createDate).Format("yyyy-MM-dd");//申请日期
			this.remark = this.setClickValue.remark;//备注
			this.unConMemo = this.setClickValue.unConMemo;//不符描述

			this.getAccountDetails(this.setClickValue);//会计对账单详情
			this.getSupplierBalance();//余额和预览页面

			if (this.$global.user.userTypeId == "1") {
				//抬头信息
				this.companyLabelShow = true;//公司
				this.comName = this.setClickValue.companyName;//公司名称
				this.inputDis = true;//不符项描述的可编辑状态
				this.supplierName = this.setClickValue.supplierName;//供应商名称
				this.$set(operator, 'delDetailsShow', false);

				//未审的会计对账单
				if (this.setClickValue.billState == 3) {
					// this.audit_show = true;//审核按钮的显示
					// this.rollBack_show = true;//退回按钮的显示
				}
				//已审的会计对账单
				else if (this.setClickValue.billState == 4) {
					this.audit_show = false;//审核按钮的显示
					this.rollBack_show = false;//退回按钮的显示
				}
			}
			this.getAuditOptionData()
		}
	},
	components: {
		"sign-option-tab": SignOptionTab
	},
	props: ["pageLayOut", "authInfo", 'setClickValue'],
	beforeMount () {
		var that = this;
		this.invoiceDetailsGridOptions = Object.assign({
			context: {
				componentParent: this
			},
			enableColResize: true,
			localeText: localeText,
			suppressRowClickSelection: true,
			onCellValueChanged: this.invoiceCellValueChanged,
			pinnedBottomRowData: this.createData(1, "Bottom"),
			isRowSelectable: function (rowNode) {
				if (that.pageLayOut == "edit") {
					if (that.setClickValue.billState > 1)
						return false;
					else if (that.setClickValue.billState === 1)
						return true;
				}
			},
			getRowStyle: function (params) {
				if (params.data.invoiceMoney == '') {
					return { 'color': 'red' };
				}
				if (params.node.rowPinned) {
					return { 'color': 'red', 'font-weight': 'bold' }
				}
			}
		}, gridOptions({ dragSelectCheckbox: true, singleSelection: true, operation: true }))
		this.invoiceDetailsColumnDefs = [
			{				headerName: "业务类型", field: "busType", editable: true, width: 100, checkboxSelection: true, cellEditorFramework: SelectorComponents,
				cellRenderer: function (params) {
					if (params.value == "1")
						return '<span class="ag-icon">普通采购</span>';
					else if (params.value == "2")
						return '<span class="ag-icon">预付款</span>';
					else if (params.value == "3")
						return '<span class="ag-icon">期初</span>';
					else if (params.value == "4")
						return '<span class="ag-icon">调整</span>';
				},
				pinned: 'left'
			},
			{ headerName: "实物对账单号", field: "gooAccNo", width: 130 },
			{				headerName: "对账金额", field: "amount", width: 130, cellRenderer: function (params) {
					if (params.value)
						return params.value.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");
					else
						return params.value;
				}
			},
			{ headerName: "发票号码", field: "invoiceNo", width: 300, editable: true, cellEditorFramework: NumericEditorComponent },
			{				headerName: "发票日期", field: "invoiceDate", width: 100, editable: true, cellEditorFramework: DatePickerComponent, cellRenderer: function (params) {
					if (params.value)
						return new Date(params.value).Format("yyyy-MM-dd");
				}
			},
			{ headerName: "发票金额", field: "invoiceMoney", width: 130, editable: true, cellEditorFramework: DecimalEditorComponent },
			//   { headerName: "操作", field: "", width: 100, cellRendererFramework: operator }
		];

	}
};

Date.prototype.Format = function (fmt) {
	var o = {
		"M+": this.getMonth() + 1, //月份 
		"d+": this.getDate(), //日 
		"H+": this.getHours(), //小时 
		"m+": this.getMinutes(), //分 
		"s+": this.getSeconds(), //秒 
		"q+": Math.floor((this.getMonth() + 3) / 3), //季度 
		"S": this.getMilliseconds() //毫秒 
	};
	if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
		if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
}
</script>
